package com.platform.api;

import com.platform.annotation.LoginUser;
import com.platform.entity.*;
import com.platform.service.*;
import com.platform.util.ApiBaseAction;
import com.platform.utils.Query;
import com.platform.utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 通知
 *
 * @author zhurusen
 * @email 524227263@qq.com
 */
@RestController
@RequestMapping("/api/topic")
public class ApiTopicController  extends ApiBaseAction {

    @Autowired
    private ApiTopicService apiTopicService;


    @RequestMapping("/list")
    public R list(@LoginUser UserVo loginUser, @RequestParam(value = "page", defaultValue = "1") Integer page) {

        //查询列表数据
        Map<String, Object> params = new HashMap<>();
        params.put("page", page);
        params.put("limit", 10);

        params.put("sidx", "id");
        params.put("order", "desc");
        Query query = new Query(params);

        List<ApiTopicVo> list = apiTopicService.selectPage(query);

        List<Map<String, Object>> reObject = new ArrayList<>();

        for (ApiTopicVo info : list) {
            Map<String, Object> map = new HashMap<>();
            map.put("id", info.getId());
            map.put("title", info.getTitle());
            map.put("createTime", info.getCreateTime());
            reObject.add(map);
        }
        return R.ok(0, "获取成功", reObject);

    }

    @RequestMapping("/info")
    public R info(@LoginUser UserVo loginUser, Long id) {

        return R.ok(0, "获取成功", apiTopicService.selectOne(id));
    }


}
